
/**
 * @function removeClass
 * @param className 类名
 * @description 清除指定样式
 */
export const removeClass: Function = (className: string): void => {
  let selected = document.getElementsByClassName(className)
  if (selected.length) {
    for (let i = 0; i < selected.length; i++) {
      selected[i].classList.toggle(className)
    }
  }

}


/**
 * @function getItemByClass
 * @param className 类名
 * @param reg 正则
 * @description 根据指定样式获取Dom元素
 */
export const getItemByClass: Function = (className: string, reg: RegExp): Element | null => {
  let selected = document.getElementsByClassName(className)
  for (let i = 0; i < selected.length; i++) {
    if (selected[i].className.match(reg)) return selected[i]
  }
  return null
}



/**
 * @function styleSetting
 * @param item style对应的对象
 * @returns style Object
 */
export const styleSetting: Function = (item): StrNumsObject => {
  return {
    'width': item.width + 'px',
    'height': item.height + 'px',
    'left': item.left + 'px',
    'top': item.top + 'px',
    'position': 'absolute',
    'z-index': item.zIndex
  }
}



/**
 * @function checkConfig
 * @param config 配置对象
 * @returns Object
 */
export const checkConfig: Function = (config): BoolStrObject => {
  if (config.zIndex < 0) return {
    status: false,
    msg: 'zIndex required > 0'
  };
  return {
    status: true,
    msg: ''
  };
}



/**
 * @function findeElement
 * @param ev 事件对象
 * @param ecallbackv 回调
 */
export const findeElement: Function = (ev, type, callback): any => {

  // 获取第一个冒泡的元素，即最上层元素
  const eventPath: Array<HTMLElement> = [...ev.path];
  if (type === 'tools') for (let i = 0; i < eventPath.length; i++) if (eventPath[i].id && !eventPath[i].id.indexOf('tools-drag')) return callback(eventPath[i], eventPath)
  if (type === 'nymo') for (let i = 0; i < eventPath.length; i++) if (eventPath[i].id && !eventPath[i].id.indexOf('nymo-child')) return callback(eventPath[i], eventPath)
  if (type === 'menu') for (let i = 0; i < eventPath.length; i++) if (eventPath[i].id && !eventPath[i].id.indexOf('clickMenu')) return callback(eventPath[i], eventPath)
  return callback(null, eventPath)

}